package com.example.demo.service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.entity.CarKeep;
import com.example.demo.entity.CarKeep2;
import com.example.demo.entity.CarNumberCompany1;
import com.example.demo.entity.CarNumberCompany2;
import com.example.demo.entity.CarsOrder;
import com.example.demo.entity.CarsOrder2;
import com.example.demo.entity.Insurance;
import com.example.demo.entity.Insurance2;
import com.example.demo.entity.MoneyCompany;
import com.example.demo.entity.MoneyCompany2;
import com.example.demo.entity.UsedCar1;
import com.example.demo.entity.UsedCar2;
import com.example.demo.entity.SaleBoutique1;
import com.example.demo.entity.SaleBoutique2;
import com.example.demo.entity.SysUser;
import com.example.demo.entity.TargetAndBackMonkeyPeople;
import com.example.demo.entity.TargetAndBackMonkeyPeople2;
import com.example.demo.entity.ThreadInput;
import com.example.demo.entity.ThreadInput2;
import com.example.demo.entity.YanBao;
import com.example.demo.entity.YanBao2;

@Service
public class ErShouCheBuComPuterService {

	private DateFormat Format = new SimpleDateFormat("yyyy-MM-dd");

	@Autowired
	private TargetAndBackMonkeyPeopleService MuBiaoservice2;

	@Autowired
	private TargetAndBackMonkeyPeopleService2 MuBiaoservice1;

	@Autowired
	private CarsOrder2Service Carservice2;
	@Autowired
	private CarsOrderService Carservice1;
	@Autowired
	private ThreadInputService threadService1;
	@Autowired
	private ThreadInput2Service threadService2;

	@Autowired
	private UsedCar1Service UsedCarDAO1;

	@Autowired
	private UsedCar2Service UsedCarDAO2;

	@Autowired
	private InsuranceService baoXianService1;

	@Autowired
	private Insurance2Service baoXianService2;
	@Autowired
	private YanBao2Service yanbaoService2;

	@Autowired
	private MoneyCompany2Service jinRongService2;

	@Autowired
	private CarNumberCompanyService2 carNumService2;

	@Autowired
	private SaleBoutique2Service saleBoutique2Service;
	@Autowired
	private CarKeep2Service carKeep2Service;

	/**
	 * @param user
	 * @return // 获取城区交付量
	 */
	public Integer UsedCarChengQuNum(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> cars = Carservice1.findByUserId(user);
		Integer num = 0;
		for (CarsOrder carsOrder : cars) {
			CarsOrder2 model = findBycarsorder(carsOrder, beginDate, endDate);
			if (model != null) {
				if ("城区".equals(model.getCarsorder().getArea())) {
					num++;
				}
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @return 获取转介绍量
	 */
	public Integer ZhuanJieShao(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> cars = Carservice1.findByUserId(user);
		Integer num = 0;
		for (CarsOrder carsOrder : cars) {
			CarsOrder2 model = findBycarsorder(carsOrder, beginDate, endDate);
			if (model != null) {
				if ("是".equals(model.getZhuanjieshao())) {
					num++;
				}
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @return //获取城郊交付量
	 */
	public Integer UsedCarChengJiaoNum(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> cars = Carservice1.findByUserId(user);
		Integer num = 0;

		for (CarsOrder carsOrder : cars) {
			CarsOrder2 model = findBycarsorder(carsOrder, beginDate, endDate);
			if (model != null) {
				if ("城郊".equals(model.getCarsorder().getArea())) {
					num++;
				} else {
					continue;
				}
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @return //获取区域外交付量
	 */
	public Integer UsedCarQuYuWaiNums(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> cars = Carservice1.findByUserId(user);
		Integer num = 0;
		for (CarsOrder carsOrder : cars) {
			CarsOrder2 model = findBycarsorder(carsOrder, beginDate, endDate);
			if (model != null) {
				if ("区域外".equals(model.getCarsorder().getArea())) {
					num++;
				}
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @return 算出新车销量
	 */
	public Integer UsedCarNums(SysUser user, Date beginDate, Date endDate) {
		return UsedCarChengJiaoNum(user, beginDate, endDate) + UsedCarChengQuNum(user, beginDate, endDate)
				+ UsedCarQuYuWaiNums(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @return //新增来电(店)留档量
	 */
	public Integer LaiDianLiuDangNums(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 threadInput2 = findByThreadInout(threadInput, beginDate, endDate);
			if (threadInput2 == null) {
				continue;
			}
			if (threadInput2.getPhone() != null || threadInput2.getWeiXin() != null) {
				if (threadInput2.getJieQia() != null) {
					if ("来电".equals(threadInput2.getJieQia()) || "来店".equals(threadInput2.getJieQia())) {
						num++;
					}
				}
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return //新增展会及外拓留档量
	 */
	public Integer zhanhuiWaituoLiuDangNums(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 threadInput2 = findByThreadInout(threadInput, beginDate, endDate);
			if (threadInput2 == null) {
				continue;
			}
			if (threadInput2.getPhone() != null || threadInput2.getWeiXin() != null) {
				if (threadInput2.getJieQia() != null) {
					if ("展会".equals(threadInput2.getJieQia()) || "外拓".equals(threadInput2.getJieQia())) {
						num++;
					}
				}
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 展厅留档量
	 */
	public Integer ZhanTingLiudangNums(SysUser user, Date beginDate, Date endDate) {
		return LaiDianLiuDangNums(user, beginDate, endDate) + zhanhuiWaituoLiuDangNums(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @return 城区成交率
	 */
	public Float ChengQuChengJiaoLv(SysUser user, Date beginDate, Date endDate) {

		if (ZhanTingLiudangNums(user, beginDate, endDate) != 0) {
			return (float) (UsedCarChengQuNum(user, beginDate, endDate) / ZhanTingLiudangNums(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @return 城郊成交率
	 */
	public Float ChengJiaoChengJiaoLv(SysUser user, Date beginDate, Date endDate) {
		if (ZhanTingLiudangNums(user, beginDate, endDate) != 0) {
			return (float) (UsedCarChengJiaoNum(user, beginDate, endDate)
					/ ZhanTingLiudangNums(user, beginDate, endDate));

		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @return 区域外成交率
	 */
	public Float QuYuWaiChengJiaoLv(SysUser user, Date beginDate, Date endDate) {
		if (ZhanTingLiudangNums(user, beginDate, endDate) != 0) {
			return (float) (UsedCarQuYuWaiNums(user, beginDate, endDate)
					/ ZhanTingLiudangNums(user, beginDate, endDate));

		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @return 新车成交率(新车销量/展厅留档量)
	 */
	public Float XinCheChengJiaoLv(SysUser user, Date beginDate, Date endDate) {
		if (ZhanTingLiudangNums(user, beginDate, endDate) != 0) {
			return (float) (UsedCarNums(user, beginDate, endDate) / ZhanTingLiudangNums(user, beginDate, endDate));

		} else {
			return (float) 0;
		}

	}

	/**
	 * @param user
	 * @return 城区来店线索
	 */
	public Integer ChengQuXianSuo1(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 threadInput2 = findByThreadInout(threadInput, beginDate, endDate);
			if (threadInput2 == null) {
				continue;
			}
			if ("来店".equals(threadInput2.getJieQia())) {
				if ("城区".equals(threadInput2.getArea())) {
					num++;
				}
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 城区来电线索
	 */
	public Integer ChengQuXianSuo(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 threadInput2 = findByThreadInout(threadInput, beginDate, endDate);
			if (threadInput2 == null) {
				continue;
			}
			if ("来电".equals(threadInput2.getJieQia())) {
				if ("城区".equals(threadInput2.getArea())) {
					num++;
				}
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 城郊来店线索
	 */
	public Integer ChengJiaoXianSuo1(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 threadInput2 = findByThreadInout(threadInput, beginDate, endDate);
			if (threadInput2 == null) {
				continue;
			}
			if ("来店".equals(threadInput2.getJieQia())) {
				if ("城郊".equals(threadInput2.getArea())) {
					num++;
				}
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 城郊来电线索
	 */
	public Integer ChengJiaoXianSuo(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 threadInput2 = findByThreadInout(threadInput, beginDate, endDate);
			if (threadInput2 == null) {
				continue;
			}
			if ("来电".equals(threadInput2.getJieQia())) {
				if ("城郊".equals(threadInput2.getArea())) {
					num++;
				}
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 区域外来店线索
	 */
	public Integer QuYuWaiXianSuo1(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 threadInput2 = findByThreadInout(threadInput, beginDate, endDate);
			if (threadInput2 == null) {
				continue;
			}
			if ("来店".equals(threadInput2.getJieQia())) {
				if ("区域外".equals(threadInput2.getArea())) {
					num++;
				}

			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 新增展会线索
	 */
	public Integer ZhanHuiXianSuo(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 threadInput2 = findByThreadInout(threadInput, beginDate, endDate);
			if (threadInput2 == null) {
				continue;
			}
			if ("展会".equals(threadInput2.getJieQia())) {
				num++;

			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 新增外拓线索
	 */
	public Integer WaiTuoXianSuo(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 threadInput2 = findByThreadInout(threadInput, beginDate, endDate);
			if (threadInput2 == null) {
				continue;
			}
			if ("外拓".equals(threadInput2.getJieQia())) {
				num++;

			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 新增展会及外拓线索
	 */
	public Integer ZhanHuiJiWaiTuoXianSuo(SysUser user, Date beginDate, Date endDate) {
		return ZhanHuiXianSuo(user, beginDate, endDate) + WaiTuoXianSuo(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @return 区域外来电线索
	 */
	public Integer QuYuWaiXianSuo(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 threadInput2 = findByThreadInout(threadInput, beginDate, endDate);
			if (threadInput2 == null) {
				continue;
			}
			if ("来电".equals(threadInput2.getJieQia())) {
				if ("区域外".equals(threadInput2.getArea())) {
					num++;
				}

			}
		}
		return num;
	}

	/**
	 * 
	 * @param user
	 * @return 新增来店线索
	 */
	public Integer LaiDian1XianSuo(SysUser user, Date beginDate, Date endDate) {
		return ChengJiaoXianSuo1(user, beginDate, endDate) + ChengQuXianSuo1(user, beginDate, endDate)
				+ QuYuWaiXianSuo1(user, beginDate, endDate);
	}

	/**
	 * 
	 * @param user
	 * @return 新增来电线索
	 */
	public Integer LaiDianXianSuo(SysUser user, Date beginDate, Date endDate) {
		return ChengJiaoXianSuo(user, beginDate, endDate) + ChengQuXianSuo(user, beginDate, endDate)
				+ QuYuWaiXianSuo(user, beginDate, endDate);
	}

	/**
	 * 
	 * @param user
	 * @return 展厅线索量
	 */
	public Integer ZhanTingXianSuo(SysUser user, Date beginDate, Date endDate) {
		return LaiDian1XianSuo(user, beginDate, endDate) + LaiDianXianSuo(user, beginDate, endDate)
				+ ZhanHuiJiWaiTuoXianSuo(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @return 首次邀约城区来店量
	 */
	public Integer firstOneChengQuLaiDian(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if ("城区".equals(model.getArea()) && "一次邀约".equals(model.getReachStore())) {
				num++;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 首次邀约城郊来店量
	 */
	public Integer firstOneChengJiaoLaiDian(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if ("城郊".equals(model.getArea()) && "一次邀约".equals(model.getReachStore())) {
				num++;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 首次邀约区域外来店量
	 */
	public Integer firstOneQuYuWaiLaiDian(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if ("区域外".equals(model.getArea()) && "一次邀约".equals(model.getReachStore())) {
				num++;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 首次邀约来店量
	 */
	public Integer firstLaiDianZongHe(SysUser user, Date beginDate, Date endDate) {

		return firstOneChengQuLaiDian(user, beginDate, endDate) + firstOneChengJiaoLaiDian(user, beginDate, endDate)
				+ firstOneQuYuWaiLaiDian(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @return 二次邀约及以上城区来店量
	 */
	public Integer SecondTwoChengQuLaiDian(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if ("城区".equals(model.getArea()) && "二次及以上邀约".equals(model.getReachStore())) {
				num++;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 二次邀约及以上城郊来店量
	 */
	public Integer SecondTwoChengJiaoLaiDian(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if ("城郊".equals(model.getArea()) && "二次及以上邀约".equals(model.getReachStore())) {
				num++;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 二次邀约及以上区域外来店量
	 */
	public Integer SecondTwoQuYuWaiLaiDian(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if ("区域外".equals(model.getArea()) && "二次及以上邀约".equals(model.getReachStore())) {
				num++;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 二次邀约及以上来店量
	 */
	public Integer SecondTwoLaiDianZongHe(SysUser user, Date beginDate, Date endDate) {
		return SecondTwoChengQuLaiDian(user, beginDate, endDate) + SecondTwoChengJiaoLaiDian(user, beginDate, endDate)
				+ SecondTwoQuYuWaiLaiDian(user, beginDate, endDate);
	}
	
	/**
	 * @return 总共邀约到店量
	 */
	public Integer YaoYueDaoDianliang(SysUser user, Date beginDate, Date endDate) {
	 Integer i=	firstLaiDianZongHe(user, beginDate, endDate)+SecondTwoLaiDianZongHe(user, beginDate, endDate);
	 return i;
	}
		

	/**
	 * @param user
	 * @return 试乘试驾数量
	 */
	public Integer ShiChengShiJiaNum(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if (model.getNumber() != null) {
				num++;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 留档率
	 */
	public Float LiuDangLv(SysUser user, Date beginDate, Date endDate) {
		if (ZhanTingXianSuo(user, beginDate, endDate) != 0) {
			return (float) ZhanTingLiudangNums(user, beginDate, endDate) / ZhanTingXianSuo(user, beginDate, endDate);

		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @return 首次邀约来店率
	 */
	public Float ShouCiYaoYueLaiDianLv(SysUser user, Date beginDate, Date endDate) {

		if (ZhanTingLiudangNums(user, beginDate, endDate) != 0) {
			return (float) firstLaiDianZongHe(user, beginDate, endDate) / ZhanTingLiudangNums(user, beginDate, endDate);

		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @return 二次及以上邀约来店率
	 */
	public Float twoYaoYueLaiDianLv(SysUser user, Date beginDate, Date endDate) {
		if (firstLaiDianZongHe(user, beginDate, endDate) != 0) {
			return (float) SecondTwoLaiDianZongHe(user, beginDate, endDate)
					/ firstLaiDianZongHe(user, beginDate, endDate);

		} else {
			return (float) 0;
		}

	}

	/**
	 * @param user
	 * @return 试乘试驾率
	 */
	public Float ShiChengShiJiaLv(SysUser user, Date beginDate, Date endDate) {
		if (ZhanTingLiudangNums(user, beginDate, endDate) != 0) {
			return (float) ShiChengShiJiaNum(user, beginDate, endDate) / ZhanTingLiudangNums(user, beginDate, endDate);

		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @return H级客户数量
	 */
	public Integer HLevel(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if ("H".equals(model.getFollowRank())) {
				num++;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return A级客户数量
	 */
	public Integer ALevel(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if ("A".equals(model.getFollowRank())) {
				num++;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return B级客户数量
	 */
	public Integer BLevel(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if ("B".equals(model.getFollowRank())) {
				num++;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return C级客户数量
	 */
	public Integer CLevel(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if ("C".equals(model.getFollowRank())) {
				num++;
			}
		}
		return num;
	}

	public Integer JiBie(String s, SysUser user, Date beginDate, Date endDate) {

		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if (s.equals(model.getFollowRank())) {
				num++;
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @return 累计意向客户级别数量
	 */
	public Integer LeiJiLeveLHeji(SysUser user, Date beginDate, Date endDate) {
		return HLevel(user, beginDate, endDate) + ALevel(user, beginDate, endDate) + BLevel(user, beginDate, endDate)
				+ CLevel(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @return 新增战败失控客户数量
	 */
	public Integer XinZengZhanBaiShiKongNum(SysUser user, Date beginDate, Date endDate) {
		List<ThreadInput> list = threadService1.findByUserId(user);
		Integer num = 0;
		for (ThreadInput threadInput : list) {
			ThreadInput2 model = findByThreadInout(threadInput, beginDate, endDate);
			if (model == null) {
				continue;
			}
			if ("战败失控".equals(model.getCustomerState())) {
				num++;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 战败失控率
	 */
	public Integer ZhanBaiShiKongLv(SysUser user, Date beginDate, Date endDate) {
		if (LeiJiLeveLHeji(user, beginDate, endDate) != 0) {
			return XinZengZhanBaiShiKongNum(user, beginDate, endDate) / LeiJiLeveLHeji(user, beginDate, endDate);

		} else {
			return 0;
		}
	}

	/**
	 * @param user
	 * @return 新车销售收入
	 */
	public Integer XinCheXiaoShouShouRu(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Integer money = 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 model = findBycarsorder(carsOrder, beginDate, endDate);
			if (model == null || model.getXiaoShouPrice() == null) {
				continue;
			}
			money += model.getXiaoShouPrice();
		}
		return money;
	}

	/**
	 * @param user
	 * @return 新车销售成本
	 */
	public Integer XinCheXiaoShouChenBen(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Integer money = 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 model = findBycarsorder(carsOrder, beginDate, endDate);
			if (model == null) {
				continue;
			}
			List<UsedCar1> cars = model.getCars2();
			String str = "";
			for (UsedCar1 car : cars) {
				str += car.getId() + ",";
			}
			if (str.indexOf(",") > 0) {
				str = str.substring(0, str.length() - 1);
			}
			String[] split = str.split(",");
			for (String string : split) {
				if (!"".equals(string)) {

					UsedCar1 UsedCar1 = UsedCarDAO1.findById(Integer.parseInt(string));
					UsedCar2 model2 = findByUsedCarInout(UsedCar1, beginDate, endDate);
					if (model2 == null) {
						continue;
					}
					money += model2.getSgjg();
				}
			}
		}
		return money;
	}

	/**
	 * @param user
	 * @return 新车销售毛利
	 */
	public Integer XinCheXiaoShouMaoLi(SysUser user, Date beginDate, Date endDate) {
		return XinCheXiaoShouShouRu(user, beginDate, endDate) - XinCheXiaoShouChenBen(user, beginDate, endDate);

	}

	/**
	 * @param user
	 * @return 新车销售毛利率
	 */
	public Float XincheXiaoShouMaoLiLv(SysUser user, Date beginDate, Date endDate) {
		float shouru = XinCheXiaoShouShouRu(user, beginDate, endDate);
		float maoli = XinCheXiaoShouMaoLi(user, beginDate, endDate);
		if (shouru != 0) {
			return (maoli / shouru);
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @return 新车交强险毛利(录入交强险金额*交强险返利点)
	 */
	public Float UsedCarJiaoQiangXianMaoLi(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 cars2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (cars2 == null) {
				continue;
			}
			if (cars2 != null && cars2.getMaiJiaoQiang() != null && cars2.getMaiBaoXian() != null) {
				List<Insurance> baoXian = cars2.getMaiBaoXian();
				if (baoXian.size() > 0) {
					if (baoXian.get(0) == null) {
						continue;
					}
					Insurance baoxian = baoXian.get(0);
					Insurance2 baoXian2 = findByBaoXian(baoxian, beginDate, endDate);
					if (baoXian2 == null) {
						continue;
					}
					if (baoXian2.getJqxfld() == null) {
						continue;
					}
					Float jqxfld = baoXian2.getJqxfld();
					num = cars2.getMaiJiaoQiang() * jqxfld;
					num += num;
				} else {
					continue;
				}
			} else {
				continue;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 新车交强险成本(录入交强险金额-交强险毛利)
	 */
	public Float UsedCarJiaoQiangXianChengBen(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		Float maoli = UsedCarJiaoQiangXianMaoLi(user, beginDate, endDate);
		for (CarsOrder carsOrder : list) {
			CarsOrder2 cars2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (cars2 == null) {
				continue;
			}
			if (cars2.getMaiJiaoQiang() != null) {
				num += cars2.getMaiJiaoQiang();
			} else {
				continue;
			}
		}

		return num - maoli;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车交强险收入(新车交强险毛利+新车交强险成本)
	 */
	public Float UsedCarJiaoQiangXianShouRu(SysUser user, Date beginDate, Date endDate) {
		return UsedCarJiaoQiangXianMaoLi(user, beginDate, endDate)
				+ UsedCarJiaoQiangXianChengBen(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车交强险毛利率(新车交强险毛利/新车交强险收入)
	 */
	public Float UsedCarJiaoQiangXianMaoLiLv(SysUser user, Date beginDate, Date endDate) {

		if (UsedCarJiaoQiangXianShouRu(user, beginDate, endDate) != 0) {

			return UsedCarJiaoQiangXianMaoLi(user, beginDate, endDate)
					/ UsedCarJiaoQiangXianShouRu(user, beginDate, endDate);
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @return 新车商业险收入(新车商业险收入-新车商业险成本)
	 */
	public Float UsedCarShangYeXianShouRu(SysUser user, Date beginDate, Date endDate) {
		return UsedCarShangYeXianMaoLi(user, beginDate, endDate) + UsedCarShangYeXianChengBen(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @return 新车商业险成本(录入商业险金额-商业险收入)
	 */
	public Float UsedCarShangYeXianChengBen(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		Float maoli = UsedCarShangYeXianMaoLi(user, beginDate, endDate);
		for (CarsOrder carsOrder : list) {
			CarsOrder2 cars2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (cars2 == null) {
				continue;
			}
			if (cars2.getMaiShangYeXian() != null) {
				num += cars2.getMaiShangYeXian();
			} else {
				continue;
			}
		}

		return num - maoli;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车商业险毛利(录入商业险金额*商业险返利点)
	 */
	public Float UsedCarShangYeXianMaoLi(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 cars2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (cars2 == null) {
				continue;
			}
			if (cars2.getMaiShangYeXian() != null) {
				List<Insurance> baoXian = cars2.getMaiBaoXian();
				if (baoXian.size() > 0) {
					Insurance baoxian = baoXian.get(0);
					Insurance2 baoXian2 = findByBaoXian(baoxian, beginDate, endDate);
					if (baoXian2 == null) {
						continue;
					}
					Float jqxfld = baoXian2.getSyxfld();
					if (jqxfld == null) {
						continue;
					}
					num += cars2.getMaiShangYeXian() * jqxfld;
				} else {
					continue;
				}
			} else {
				continue;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车商业险毛利率(新车商业险毛利/新车商业险收入)
	 */
	public Float UsedCarShangYeXianMaoLiLv(SysUser user, Date beginDate, Date endDate) {
		if (UsedCarShangYeXianShouRu(user, beginDate, endDate) != 0) {
			return UsedCarShangYeXianMaoLi(user, beginDate, endDate) / UsedCarShangYeXianShouRu(user, beginDate, endDate);

		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车精品销售收入(精品材料价格+精品工时价格)
	 */
	public Float UsedCarJingPinXiaoShouShouRu(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiJingPin().size() > 0 || carsOrder2.getMaiJingPin() != null) {
				List<SaleBoutique1> jingPin = carsOrder2.getMaiJingPin();
				for (SaleBoutique1 saleBoutique1 : jingPin) {
					SaleBoutique2 salebou2 = findByJingPin(saleBoutique1, beginDate, endDate);
					if (salebou2 == null) {
						continue;
					}
					if (salebou2.getCaiLiaoPrice() == null || salebou2.getGongShiPrice() == null) {
						continue;
					}
					num += salebou2.getCaiLiaoPrice() + salebou2.getGongShiPrice();
				}
			} else {
				continue;
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车精品销售成本(精品材料成本+精品工时成本)
	 */
	public Float UsedCarJingPinXiaoShouChengBen(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiJingPin().size() > 0 || carsOrder2.getMaiJingPin() != null) {
				List<SaleBoutique1> jingPin = carsOrder2.getMaiJingPin();
				for (SaleBoutique1 saleBoutique1 : jingPin) {
					if (findByJingPin(saleBoutique1, beginDate, endDate) == null) {
						continue;
					}
					SaleBoutique2 salebou2 = findByJingPin(saleBoutique1, beginDate, endDate);
					if (salebou2.getCaiLiaoCost() == null || salebou2.getGongShiCost() == null) {
						continue;
					}
					num += salebou2.getCaiLiaoCost() + salebou2.getGongShiCost();
				}
			} else {
				continue;
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车精品销售毛利(新车精品销售收入-新车精品销售成本)
	 */
	public Float UsedCarJingPinXiaoShouMaoLi(SysUser user, Date beginDate, Date endDate) {
		return UsedCarJingPinXiaoShouShouRu(user, beginDate, endDate)
				- UsedCarJingPinXiaoShouChengBen(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车精品销售毛利率(新车精品销售毛利/新车精品销售收入)
	 */
	public Float UsedCarJingPinXiaoShouMaoLiLv(SysUser user, Date beginDate, Date endDate) {
		if (UsedCarJingPinXiaoShouShouRu(user, beginDate, endDate) != 0) {

			return UsedCarJingPinXiaoShouMaoLi(user, beginDate, endDate)
					/ UsedCarJingPinXiaoShouShouRu(user, beginDate, endDate);
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车精品赠送成本(精品材料成本+精品工时成本)
	 */
	public Float UsedCarJingPinZengSongChengBen(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiJingPin().size() > 0 || carsOrder2.getMaiJingPin() != null) {
				List<SaleBoutique1> jingPin = carsOrder2.getZengJingPin();
				for (SaleBoutique1 saleBoutique1 : jingPin) {
					SaleBoutique2 salebou2 = findByJingPin(saleBoutique1, beginDate, endDate);
					num += salebou2.getCaiLiaoCost() + salebou2.getGongShiCost();
				}
			} else {
				continue;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车金融服务毛利(输入的金融金额*金融公司返利点)
	 */
	public Float UsedCarJinRongFuWuMaoLi(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 cars2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (cars2 == null) {
				continue;
			}
			if (cars2.getMaiJinRong() != null) {
				List<MoneyCompany> baoXian = cars2.getMaiJinRong();
				if (baoXian.size() > 0) {
					MoneyCompany baoxian = baoXian.get(0);
					MoneyCompany2 baoXian2 = findByJinRong(baoxian, beginDate, endDate);
					if (baoXian2 == null || baoXian2.getMonkeyBackMoney() == null) {
						continue;
					}
					Float fld = baoXian2.getMonkeyBackMoney();
					num += cars2.getXiaoShouJinRongMoney() * fld;
				}
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 新车金融成本(录入金融金额-金融毛利)
	 */
	public Float UsedCarJinRongChengBen(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 cars2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (cars2 == null) {
				continue;
			}
			if (cars2.getXiaoShouJinRongMoney() != null) {
				num += cars2.getXiaoShouJinRongMoney();
			}
		}
		return num - UsedCarJiaoQiangXianMaoLi(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车金融服务收入（成本+毛利）
	 */
	public Float UsedCarJinRongShouRu(SysUser user, Date beginDate, Date endDate) {
		return UsedCarJinRongChengBen(user, beginDate, endDate) + UsedCarJinRongFuWuMaoLi(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车金融服务毛利率（毛利/收入）
	 */
	public Float UsedCarJinRongMaoLiLv(SysUser user, Date beginDate, Date endDate) {
		if (UsedCarJinRongShouRu(user, beginDate, endDate) != 0) {
			return UsedCarJinRongFuWuMaoLi(user, beginDate, endDate) / UsedCarJinRongShouRu(user, beginDate, endDate);

		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车代办上牌毛利(输入的车牌公司金额*车牌公司返利点)
	 */
	public Float UsedCarDaiBanShangPaiMaoLi(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 cars2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (cars2 == null) {
				continue;
			}
			if (cars2.getMaiChePai() != null) {
				List<CarNumberCompany1> baoXian = cars2.getMaiChePai();
				if (baoXian.size() > 0) {
					CarNumberCompany1 baoxian = baoXian.get(0);
					CarNumberCompany2 baoXian2 = findByChePai(baoxian, beginDate, endDate);
					if (baoXian2.getOnCardBackMoney() != null && cars2.getXiaoShouChePaiMoney() != null) {

						Float fld = baoXian2.getOnCardBackMoney();
						num += cars2.getXiaoShouChePaiMoney() * fld;
					} else {
						continue;
					}
				}
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @return 新车代办上牌成本(录入车牌金额-车牌毛利)
	 */
	public Float UsedCarDaiBanShangPaiChengBen(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 cars2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (cars2 == null) {
				continue;
			}
			if (cars2.getXiaoShouChePaiMoney() != null) {
				num += cars2.getXiaoShouChePaiMoney();
			}
		}
		return num - UsedCarDaiBanShangPaiMaoLi(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车代办上牌收入（成本+毛利）
	 */
	public Float UsedCarDaiBanShangPaiShouRu(SysUser user, Date beginDate, Date endDate) {
		return UsedCarDaiBanShangPaiChengBen(user, beginDate, endDate)
				+ UsedCarDaiBanShangPaiMaoLi(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车代办上牌毛利率（毛利/收入）
	 */
	public Float UsedCarDaiBanShangPaiMaoLiLv(SysUser user, Date beginDate, Date endDate) {

		if (UsedCarDaiBanShangPaiShouRu(user, beginDate, endDate) != 0) {
			return UsedCarDaiBanShangPaiMaoLi(user, beginDate, endDate)
					/ UsedCarDaiBanShangPaiShouRu(user, beginDate, endDate);

		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车保养套餐收入(保养套餐价格)
	 */
	public Float UsedCarBaoYangTaoCanShouRu(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiBaoYang().size() > 0 || carsOrder2.getMaiBaoYang() != null) {
				List<CarKeep> jingPin = carsOrder2.getMaiBaoYang();
				for (CarKeep saleBoutique1 : jingPin) {
					if (findByBaoYang(saleBoutique1, beginDate, endDate) == null) {
						continue;
					}
					CarKeep2 salebou2 = findByBaoYang(saleBoutique1, beginDate, endDate);
					if (salebou2.getPrice() == null) {
						continue;
					}
					num += salebou2.getPrice();
				}
			} else {
				continue;
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车保养套餐成本(保养套餐成本)
	 */
	public Float UsedCarBaoYangTaoCanChengBen(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiBaoYang().size() > 0 || carsOrder2.getMaiBaoYang() != null) {
				List<CarKeep> jingPin = carsOrder2.getMaiBaoYang();
				for (CarKeep saleBoutique1 : jingPin) {
					CarKeep2 salebou2 = findByBaoYang(saleBoutique1, beginDate, endDate);
					num += salebou2.getCost();
				}
			} else {
				continue;
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 保养套餐毛利(保养套餐收入-保养套餐成本)
	 */
	public Float UsedCarBaoYangTaoCanMaoLi(SysUser user, Date beginDate, Date endDate) {
		return UsedCarBaoYangTaoCanShouRu(user, beginDate, endDate)
				- UsedCarBaoYangTaoCanChengBen(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 保养套餐毛利率(保养套餐毛利/保养套餐收入)
	 */
	public Float UsedCarBaoYangTaoCanMaoLiLv(SysUser user, Date beginDate, Date endDate) {
		if (UsedCarBaoYangTaoCanShouRu(user, beginDate, endDate) != 0) {
			return UsedCarBaoYangTaoCanMaoLi(user, beginDate, endDate)
					/ UsedCarBaoYangTaoCanShouRu(user, beginDate, endDate);
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车延保收入(延保价格)
	 */
	public Float UsedCarYanBaoShouRu(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiYanBao().size() > 0 || carsOrder2.getMaiYanBao() != null) {
				List<YanBao> jingPin = carsOrder2.getMaiYanBao();
				for (YanBao saleBoutique1 : jingPin) {
					YanBao2 salebou2 = findByYanBao(saleBoutique1, beginDate, endDate);
					num += salebou2.getYanBaoPrice();
				}
			} else {
				continue;
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车延保成本(延保成本)
	 */
	public Float UsedCarYanBaoChengBen(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		Float num = (float) 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiYanBao().size() > 0 || carsOrder2.getMaiYanBao() != null) {
				List<YanBao> jingPin = carsOrder2.getMaiYanBao();
				for (YanBao saleBoutique1 : jingPin) {
					YanBao2 salebou2 = findByYanBao(saleBoutique1, beginDate, endDate);
					num += salebou2.getYanBaoCost();
				}
			} else {
				continue;
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车延保毛利（新车延保收入-新车延保成本）
	 */
	public Float UsedCarYanBaoMaoLi(SysUser user, Date beginDate, Date endDate) {
		return UsedCarYanBaoShouRu(user, beginDate, endDate) - UsedCarYanBaoChengBen(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车延保毛利率（新车延保毛利/新车延保收入）
	 */
	public Float UsedCarYanBaoMaoLiLv(SysUser user, Date beginDate, Date endDate) {
		if (UsedCarYanBaoShouRu(user, beginDate, endDate) != 0) {
			return UsedCarYanBaoMaoLi(user, beginDate, endDate) / UsedCarYanBaoShouRu(user, beginDate, endDate);
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车交付目标台数
	 */
	public Integer XinCheJiaoFuMuBiaoTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<TargetAndBackMonkeyPeople2> list = MuBiaoservice1.findByUser(user);
		int num = 0;
		for (TargetAndBackMonkeyPeople2 tar1 : list) {
			if (tar1 != null) {
				if (isEffectiveDate(tar1.getDate(), beginDate, endDate)) {
					if (findByRenYuanMuBiao(tar1, beginDate, endDate) != null) {
						TargetAndBackMonkeyPeople tar2 = findByRenYuanMuBiao(tar1, beginDate, endDate);
						num = tar2.getMyAllBuyCarTarget();
					} else {
						return 0;
					}
				}
			} else {
				return 0;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车交付目标台数达成率
	 */
	public Float XinCheJiaoFuMuBiaoTaiShuDaChengLv(SysUser user, Date beginDate, Date endDate) {
		float mubiao = XinCheJiaoFuMuBiaoTaiShu(user, beginDate, endDate);
		float shiji = UsedCarNums(user, beginDate, endDate);
		if (mubiao != 0) {
			return (shiji / mubiao);
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车精品销售目标台数
	 */
	public Integer XinCheJingPinXiaoShouMuBiaoTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<TargetAndBackMonkeyPeople2> list = MuBiaoservice1.findByUser(user);
		int num = 0;
		for (TargetAndBackMonkeyPeople2 tar1 : list) {
			if (tar1 != null) {
				if (isEffectiveDate(tar1.getDate(), beginDate, endDate)) {
					if (findByRenYuanMuBiao(tar1, beginDate, endDate) != null) {
						TargetAndBackMonkeyPeople tar2 = findByRenYuanMuBiao(tar1, beginDate, endDate);
						num = tar2.getMyBoutiqueTarget();
					} else {
						return 0;
					}
				}
			} else {
				return 0;
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车金融车目标台数
	 */
	public Integer XinCheJinRongCheMuBiaoTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<TargetAndBackMonkeyPeople2> list = MuBiaoservice1.findByUser(user);
		int num = 0;
		for (TargetAndBackMonkeyPeople2 tar1 : list) {
			if (tar1 != null) {
				if (isEffectiveDate(tar1.getDate(), beginDate, endDate)) {
					if (findByRenYuanMuBiao(tar1, beginDate, endDate) != null) {
						TargetAndBackMonkeyPeople tar2 = findByRenYuanMuBiao(tar1, beginDate, endDate);
						num = tar2.getMyMokeyCarTarget();
					} else {
						return 0;
					}
				}
			} else {
				return 0;
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车精品销售实际台数
	 */
	public Integer XinCheJingPinXiaoShouShiJiTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		int num = 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiJingPin() != null) {
				num++;
			} else {
				continue;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车金融车销售实际台数
	 */
	public Integer XinCheJinRongCheXiaoShouShiJiTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		int num = 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiJinRong() != null) {
				num++;
			} else {
				continue;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车保养套餐销售目标台数
	 */
	public Integer XinCheBaoYangTaoCanXiaoShouMuBiaoTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<TargetAndBackMonkeyPeople2> list = MuBiaoservice1.findByUser(user);
		int num = 0;
		for (TargetAndBackMonkeyPeople2 tar1 : list) {
			if (tar1 != null) {
				if (isEffectiveDate(tar1.getDate(), beginDate, endDate)) {
					if (findByRenYuanMuBiao(tar1, beginDate, endDate) != null) {
						TargetAndBackMonkeyPeople tar2 = findByRenYuanMuBiao(tar1, beginDate, endDate);
						num = tar2.getMyInsuranceSetTarget();
					} else {
						return 0;
					}
				}
			} else {
				return 0;
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车保养套餐销售实际台数
	 */
	public Integer XinCheBaoYangTaoCanXiaoShouShiJiTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		int num = 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiBaoYang() != null) {
				num++;
			} else {
				continue;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车保养套餐销售目标达成率
	 */
	public Float XinCheBaoYangTaoCanMuBiaoDaChengLv(SysUser user, Date beginDate, Date endDate) {
		if (XinCheBaoYangTaoCanXiaoShouShiJiTaiShu(user, beginDate, endDate) != 0) {
			return (float) (XinCheBaoYangTaoCanXiaoShouMuBiaoTaiShu(user, beginDate, endDate)
					/ XinCheBaoYangTaoCanXiaoShouShiJiTaiShu(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车保养套餐销售率
	 */
	public Float XinCheBaoYangTaoCanXiaoShouLv(SysUser user, Date beginDate, Date endDate) {
		if (UsedCarNums(user, beginDate, endDate) != 0) {
			return (float) (XinCheBaoYangTaoCanXiaoShouShiJiTaiShu(user, beginDate, endDate)
					/ UsedCarNums(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车延保销售目标台数
	 */
	public Integer XinCheYanBaoXiaoShouMuBiaoTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<TargetAndBackMonkeyPeople2> list = MuBiaoservice1.findByUser(user);
		int num = 0;
		for (TargetAndBackMonkeyPeople2 tar1 : list) {
			if (tar1 != null) {
				if (isEffectiveDate(tar1.getDate(), beginDate, endDate)) {
					if (findByRenYuanMuBiao(tar1, beginDate, endDate) != null) {
						TargetAndBackMonkeyPeople tar2 = findByRenYuanMuBiao(tar1, beginDate, endDate);
						num = tar2.getMylengthenInsuranceTarget();
					} else {
						return 0;
					}
				}
			} else {
				return 0;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车交强险目标台数
	 */
	public Integer XinCheJiaoQiangXianMuBiaoTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<TargetAndBackMonkeyPeople2> list = MuBiaoservice1.findByUser(user);
		int num = 0;
		for (TargetAndBackMonkeyPeople2 tar1 : list) {
			if (tar1 != null) {
				if (isEffectiveDate(tar1.getDate(), beginDate, endDate)) {
					if (findByRenYuanMuBiao(tar1, beginDate, endDate) != null) {
						TargetAndBackMonkeyPeople tar2 = findByRenYuanMuBiao(tar1, beginDate, endDate);
						num = tar2.getMyInsuranceTarget();
					} else {
						return 0;
					}
				}
			} else {
				return 0;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车商业险目标台数
	 */
	public Integer XinCheShangYeXianMuBiaoTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<TargetAndBackMonkeyPeople2> list = MuBiaoservice1.findByUser(user);
		int num = 0;
		for (TargetAndBackMonkeyPeople2 tar1 : list) {
			if (tar1 != null) {
				if (isEffectiveDate(tar1.getDate(), beginDate, endDate)) {
					if (findByRenYuanMuBiao(tar1, beginDate, endDate) != null) {
						TargetAndBackMonkeyPeople tar2 = findByRenYuanMuBiao(tar1, beginDate, endDate);
						num = tar2.getMyInsuranceTargetS();
					} else {
						return 0;
					}
				}
			} else {
				return 0;
			}
		}
		return num;

	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车代办上牌目标台数
	 */
	public Integer XinCheDaiBanShangPaiMuBiaoTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<TargetAndBackMonkeyPeople2> list = MuBiaoservice1.findByUser(user);
		int num = 0;
		for (TargetAndBackMonkeyPeople2 tar1 : list) {
			if (tar1 != null) {
				if (isEffectiveDate(tar1.getDate(), beginDate, endDate)) {
					if (findByRenYuanMuBiao(tar1, beginDate, endDate) != null) {
						TargetAndBackMonkeyPeople tar2 = findByRenYuanMuBiao(tar1, beginDate, endDate);
						num = tar2.getXinChengDaiBanShu();
					} else {
						return 0;
					}
				}
			} else {
				return 0;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车交强险实际台数
	 */
	public Integer XinCheJiaoQiangXianShiJiTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		int num = 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiJiaoQiang() > 0) {
				num++;
			} else {
				continue;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车代办上牌实际台数
	 */
	public Integer XinCheDaiBanShangPaiShiJiTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		int num = 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null || carsOrder2.getXiaoShouChePaiMoney() == null) {
				continue;
			}
			if (carsOrder2.getXiaoShouChePaiMoney() > 0) {
				num++;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车代办上牌目标达成率
	 */
	public Float XinCheDaiBanShangPaiMuBiaoDaChengLv(SysUser user, Date beginDate, Date endDate) {
		if (XinCheDaiBanShangPaiMuBiaoTaiShu(user, beginDate, endDate) != 0) {
			return (float) (XinCheDaiBanShangPaiShiJiTaiShu(user, beginDate, endDate)
					/ XinCheDaiBanShangPaiMuBiaoTaiShu(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车商业险实际台数
	 */
	public Integer XinCheShangYeXianShiJiTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		int num = 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiShangYeXian() > 0) {
				num++;
			} else {
				continue;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车交强险目标达成率
	 */
	public Float XinCheJiaoQiangXianMuBiaoDaChengLv(SysUser user, Date beginDate, Date endDate) {
		if (XinCheJiaoQiangXianMuBiaoTaiShu(user, beginDate, endDate) != 0) {
			return (float) (XinCheJiaoQiangXianShiJiTaiShu(user, beginDate, endDate)
					/ XinCheJiaoQiangXianMuBiaoTaiShu(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车代办上牌率
	 */
	public Float XinCheDaiBanShangPaiLv(SysUser user, Date beginDate, Date endDate) {
		if (UsedCarNums(user, beginDate, endDate) != 0) {
			return (float) (XinCheDaiBanShangPaiShiJiTaiShu(user, beginDate, endDate)
					/ UsedCarNums(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车商业险目标达成率
	 */
	public Float XinCheShangYeXianMuBiaoDaChengLv(SysUser user, Date beginDate, Date endDate) {
		if (XinCheShangYeXianMuBiaoTaiShu(user, beginDate, endDate) != 0) {
			return (float) (XinCheShangYeXianShiJiTaiShu(user, beginDate, endDate)
					/ XinCheShangYeXianMuBiaoTaiShu(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车交强险投保率
	 */
	public Float XinCheJiaoQiangXianTouBaoLv(SysUser user, Date beginDate, Date endDate) {
		if (UsedCarNums(user, beginDate, endDate) != 0) {
			return (float) (XinCheJiaoQiangXianShiJiTaiShu(user, beginDate, endDate)
					/ UsedCarNums(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车商业险投保率
	 */
	public Float XinCheShangYeXianTouBaoLv(SysUser user, Date beginDate, Date endDate) {
		if (UsedCarNums(user, beginDate, endDate) != 0) {
			return (float) (XinCheShangYeXianShiJiTaiShu(user, beginDate, endDate)
					/ UsedCarNums(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车延保销售实际台数
	 */
	public Integer XinCheYanBaoXiaoShouShiJiTaiShu(SysUser user, Date beginDate, Date endDate) {
		List<CarsOrder> list = Carservice1.findByUserId(user);
		int num = 0;
		for (CarsOrder carsOrder : list) {
			CarsOrder2 carsOrder2 = findBycarsorder(carsOrder, beginDate, endDate);
			if (carsOrder2 == null) {
				continue;
			}
			if (carsOrder2.getMaiYanBao() != null) {
				num++;
			} else {
				continue;
			}
		}
		return num;
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车延保销售目标达成率
	 */
	public Float XinCheYanBaoMuBiaoDaChengLv(SysUser user, Date beginDate, Date endDate) {
		if (XinCheYanBaoXiaoShouShiJiTaiShu(user, beginDate, endDate) != 0) {
			return (float) (XinCheYanBaoXiaoShouMuBiaoTaiShu(user, beginDate, endDate)
					/ XinCheYanBaoXiaoShouShiJiTaiShu(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车延保销售率
	 */
	public Float XinCheYanBaoXiaoShouLv(SysUser user, Date beginDate, Date endDate) {
		if (UsedCarNums(user, beginDate, endDate) != 0) {
			return (float) (XinCheYanBaoXiaoShouShiJiTaiShu(user, beginDate, endDate)
					/ UsedCarNums(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车金融车目标达成率
	 */
	public Float XinCheJinRongCheMuBiaoDaChengLv(SysUser user, Date beginDate, Date endDate) {
		if (XinCheJinRongCheMuBiaoTaiShu(user, beginDate, endDate) != 0) {
			return (float) (XinCheJinRongCheXiaoShouShiJiTaiShu(user, beginDate, endDate)
					/ XinCheJinRongCheMuBiaoTaiShu(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车金融车渗透率
	 */
	public Float XinCheJinRongCheShenTouLv(SysUser user, Date beginDate, Date endDate) {
		if (UsedCarNums(user, beginDate, endDate) != 0) {
			return (float) (XinCheJinRongCheXiaoShouShiJiTaiShu(user, beginDate, endDate)
					/ UsedCarNums(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车精品销售目标达成率
	 */
	public Float XinCheJingPinXiaoShouMuBiaoDaChengLv(SysUser user, Date beginDate, Date endDate) {
		if (XinCheJingPinXiaoShouMuBiaoTaiShu(user, beginDate, endDate) != 0) {
			return (float) (XinCheJingPinXiaoShouShiJiTaiShu(user, beginDate, endDate)
					/ XinCheJingPinXiaoShouMuBiaoTaiShu(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 新车精品销售率
	 */
	public Float XinCheJingPinXiaoShouLv(SysUser user, Date beginDate, Date endDate) {
		if (UsedCarNums(user, beginDate, endDate) != 0) {
			return (float) (XinCheJingPinXiaoShouShiJiTaiShu(user, beginDate, endDate)
					/ UsedCarNums(user, beginDate, endDate));
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 销售综合收入
	 */
	public Float XiaoShouZongHeShouRu(SysUser user, Date beginDate, Date endDate) {
		return XinCheXiaoShouShouRu(user, beginDate, endDate) + UsedCarJiaoQiangXianShouRu(user, beginDate, endDate)
				+ UsedCarShangYeXianShouRu(user, beginDate, endDate)
				+ UsedCarJingPinXiaoShouShouRu(user, beginDate, endDate) + UsedCarJinRongShouRu(user, beginDate, endDate)
				+ UsedCarBaoYangTaoCanShouRu(user, beginDate, endDate)
				+ UsedCarDaiBanShangPaiShouRu(user, beginDate, endDate) + UsedCarYanBaoShouRu(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 衍生业务总收入
	 */
	public Integer YanShengYeWuZongHeShouRu(SysUser user, Date beginDate, Date endDate) {
		return (int) (UsedCarJiaoQiangXianShouRu(user, beginDate, endDate)
				+ UsedCarShangYeXianShouRu(user, beginDate, endDate)
				+ UsedCarJingPinXiaoShouShouRu(user, beginDate, endDate) + UsedCarJinRongShouRu(user, beginDate, endDate)
				+ UsedCarBaoYangTaoCanShouRu(user, beginDate, endDate)
				+ UsedCarDaiBanShangPaiShouRu(user, beginDate, endDate) + UsedCarYanBaoShouRu(user, beginDate, endDate));
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 销售综合成本
	 */
	public Float XiaoShouZongHeChengBen(SysUser user, Date beginDate, Date endDate) {
		return XinCheXiaoShouChenBen(user, beginDate, endDate) + UsedCarJiaoQiangXianChengBen(user, beginDate, endDate)
				+ UsedCarShangYeXianChengBen(user, beginDate, endDate)
				+ UsedCarJingPinXiaoShouChengBen(user, beginDate, endDate)
				+ UsedCarJinRongChengBen(user, beginDate, endDate)
				+ UsedCarBaoYangTaoCanChengBen(user, beginDate, endDate)
				+ UsedCarDaiBanShangPaiChengBen(user, beginDate, endDate)
				+ UsedCarYanBaoChengBen(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 销售综合毛利
	 */
	public Float XiaoShouZongHeMaoLi(SysUser user, Date beginDate, Date endDate) {
		return XiaoShouZongHeShouRu(user, beginDate, endDate) - XiaoShouZongHeChengBen(user, beginDate, endDate);
	}

	/**
	 * @param user
	 * @param beginDate
	 * @param endDate
	 * @return 销售综合毛利率
	 */
	public Float XiaoShouZongHeMaoLiLv(SysUser user, Date beginDate, Date endDate) {
		if (XiaoShouZongHeShouRu(user, beginDate, endDate) != 0) {
			return XiaoShouZongHeMaoLi(user, beginDate, endDate) / XiaoShouZongHeShouRu(user, beginDate, endDate);
		} else {
			return (float) 0;
		}
	}

	/**
	 * @param baoxian
	 * @param beginDate
	 * @param endDate
	 * @return 通过金融公司1找到2
	 */
	private MoneyCompany2 findByJinRong(MoneyCompany baoXian1, Date beginDate, Date endDate) {
		MoneyCompany2 baoXian3=jinRongService2.findByMoney2(baoXian1.getId());
		//List<MoneyCompany2> baoXian2 = jinRongService2.findByMoney(baoXian1);
		if (baoXian3 != null) {
//			MoneyCompany2 baoXian = new MoneyCompany2();
//			Integer id = 0;
//			for (MoneyCompany2 y : baoXian2) {
//				if (id < y.getId()) {
//					id = y.getId();
//					baoXian = y;
//				}
//			}
			boolean b = isEffectiveDate(baoXian3.getBeginDate(), beginDate, endDate);
			if (b) {
				return baoXian3;
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

	/**
	 * @param baoxian
	 * @param beginDate
	 * @param endDate
	 * @return 通过车牌公司1找到2
	 */
	private CarNumberCompany2 findByChePai(CarNumberCompany1 carNum1, Date beginDate, Date endDate) {
		CarNumberCompany2 company2 = carNumService2.findByCarNumberCompany2(carNum1.getId());
		//List<CarNumberCompany2> baoXian2 = carNumService2.findByCarNumberCompany(carNum1);
		if (company2 != null) {
//			CarNumberCompany2 baoXian = new CarNumberCompany2();
//			Integer id = 0;
//			for (CarNumberCompany2 y : baoXian2) {
//				if (id < y.getId()) {
//					id = y.getId();
//					baoXian = y;
//				}
//			}
			boolean b = isEffectiveDate(company2.getBeginDate(), beginDate, endDate);
			if (b) {
				return company2;
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

	/**
	 * 3 通过车辆订交1表找二表唯一
	 * 
	 * @return
	 */
	public CarsOrder2 findBycarsorder(CarsOrder car, Date beginDate, Date endDate) {
		//List<CarsOrder2> cars2 = Carservice2.findByCarsorder(car);
		//List<CarsOrder2> cars3 = Carservice2.findByCarsorderId(car.getId());
		CarsOrder2 cars3 = Carservice2.findByCarsorderId(car.getId());
		if (cars3 != null) {
//			CarsOrder2 cars = new CarsOrder2();
//			Integer id = 1;
//			for (CarsOrder2 y : cars2) {
//				if (y == null) {
//					continue;
//				}
//				if (id < y.getId()) {
//					id = y.getId();
//				}
//			}
//			cars = Carservice2.findById(id);
			boolean b = isEffectiveDate(cars3.getBeginDate(), beginDate, endDate);
			if (b) {
				return cars3;
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

	/**
	 * 3 通过人员目标录入1表找二表唯一
	 * 
	 * @return
	 */
	public TargetAndBackMonkeyPeople findByRenYuanMuBiao(TargetAndBackMonkeyPeople2 car, Date beginDate, Date endDate) {
		TargetAndBackMonkeyPeople cars3=MuBiaoservice2.findByUser1Id2(car.getId());
		//List<TargetAndBackMonkeyPeople> cars2 = MuBiaoservice2.findByUser1(car);
		if (cars3 != null) {
//			TargetAndBackMonkeyPeople cars = new TargetAndBackMonkeyPeople();
//			Integer id = 1;
//			for (TargetAndBackMonkeyPeople y : cars2) {
//				if (id < y.getId()) {
//					id = y.getId();
//				}
//			}
//			cars = MuBiaoservice2.findById(id);
			return cars3;
		} else {
			return null;
		}
	}

	/**
	 * 通过线索框1表找到2表
	 * 
	 * @return
	 */
	public ThreadInput2 findByThreadInout(ThreadInput car, Date beginDate, Date endDate) {
		//List<ThreadInput2> cars2 = threadService2.findByThread(car);
		ThreadInput2 th2=threadService2.findByThread2(car.getId());
		if (th2 != null) {
//			ThreadInput2 cars = new ThreadInput2();
//			Integer id = 0;
//			for (ThreadInput2 y : cars2) {
//				if (id < y.getId()) {
//					id = y.getId();
//					cars = y;
//				}
//			}
			boolean b = isEffectiveDate(th2.getBeginDate(), beginDate, endDate);
			if (b) {
				return th2;
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

	/**
	 * 通过车型1表找到2表
	 * 
	 * @return
	 */
	public UsedCar2 findByUsedCarInout(UsedCar1 car, Date beginDate, Date endDate) {
		UsedCar2 cars3=UsedCarDAO2.findByUsedCar2(car.getId());
		//List<UsedCar2> cars2 = UsedCarDAO2.findByUsedCar(car);
		if (cars3 != null) {
//			UsedCar2 cars = new UsedCar2();
//			Integer id = 0;
//			for (UsedCar2 y : cars2) {
//				if (id < y.getId()) {
//					id = y.getId();
//					cars = y;
//				}
//			}
			boolean b = isEffectiveDate(cars3.getStartDays(), beginDate, endDate);
			if (b) {
				return cars3;
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

	/**
	 * 通过保险1表找到2表
	 * 
	 * @return
	 */
	public Insurance2 findByBaoXian(Insurance baoXian1, Date beginDate, Date endDate) {
		Insurance2 baoXian3=baoXianService2.findByInsurance2(baoXian1.getId());
		//List<Insurance2> baoXian2 = baoXianService2.findByInsurance(baoXian1);
		if (baoXian3 != null) {
//			Insurance2 baoXian = new Insurance2();
//			Integer id = 0;
//			for (Insurance2 y : baoXian2) {
//				if (id < y.getId()) {
//					id = y.getId();
//					baoXian = y;
//				}
//			}
			return baoXian3;
		} else {
			return null;
		}
	}

	/**
	 * 通过延保1表找到2表
	 * 
	 * @return
	 */
	public YanBao2 findByYanBao(YanBao baoXian1, Date beginDate, Date endDate) {
		Integer yanBaoid = baoXian1.getId();
		YanBao2 yan2=yanbaoService2.findByYanBaoId2(yanBaoid);
	//	List<YanBao2> baoXian2 = yanbaoService2.findByYanBaoId(yanBaoid);
		if (yan2 != null) {
//			YanBao2 baoXian = new YanBao2();
//			Integer id = 0;
//			for (YanBao2 y : baoXian2) {
//				if (id < y.getId()) {
//					id = y.getId();
//					baoXian = y;
//				}
//			}
			boolean b = isEffectiveDate(yan2.getBeginDate(), beginDate, endDate);
			if (b) {
				return yan2;
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

	/**
	 * 通过精品1表找到2表
	 * 
	 * @return
	 */
	public SaleBoutique2 findByJingPin(SaleBoutique1 baoXian1, Date beginDate, Date endDate) {
		SaleBoutique2 sale2=saleBoutique2Service.findBySaleBoutique2(baoXian1.getId());
		//List<SaleBoutique2> baoXian2 = saleBoutique2Service.findBySaleBoutique(baoXian1);
		if (sale2 != null) {
//			SaleBoutique2 baoXian = new SaleBoutique2();
//			Integer id = 0;
//			for (SaleBoutique2 y : baoXian2) {
//				if (id < y.getId()) {
//					id = y.getId();
//					baoXian = y;
//				}
//			}
			boolean b = isEffectiveDate(sale2.getStartDays(), beginDate, endDate);
			if (b) {
				return sale2;
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

	/**
	 * 通过保养套餐1表找到2表
	 * 
	 * @return
	 */
	public CarKeep2 findByBaoYang(CarKeep baoXian1, Date beginDate, Date endDate) {
		CarKeep2 th2=carKeep2Service.findBycarKeep(baoXian1.getId());
		//List<CarKeep2> baoXian2 = carKeep2Service.findByCarKeep(baoXian1);
		if (th2 != null) {
//			CarKeep2 baoXian = new CarKeep2();
//			Integer id = 0;
//			for (CarKeep2 y : baoXian2) {
//				if (id < y.getId()) {
//					id = y.getId();
//					baoXian = y;
//				}
//			}
			boolean b = isEffectiveDate(th2.getBeginDate(), beginDate, endDate);
			if (b) {
				return th2;
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

	/**
	 * 
	 * @param nowTime   当前时间
	 * @param startTime 开始时间
	 * @param endTime   结束时间
	 * @return
	 * @author 判断当前时间在时间区间内
	 */
	public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
		if (nowTime.getTime() == startTime.getTime() || nowTime.getTime() == endTime.getTime()) {
			return true;
		}

		Calendar date = Calendar.getInstance();
		date.setTime(nowTime);

		Calendar begin = Calendar.getInstance();
		begin.setTime(startTime);

		Calendar end = Calendar.getInstance();
		end.setTime(endTime);

		if (date.after(begin) && date.before(end)) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * @return 上个月第一天
	 */
	public String ShangYuefirstMonth() {

		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

		Calendar calendar = Calendar.getInstance();

		calendar.add(Calendar.MONTH, -1);

		calendar.set(Calendar.DAY_OF_MONTH, 1);

		return format.format(calendar.getTime());

	}

	/**
	 * @return 上个月最后一天
	 */
	public String ShangYuelastMonth() {

		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");

		Calendar calendar = Calendar.getInstance();

		int month = calendar.get(Calendar.MONTH);

		calendar.set(Calendar.MONTH, month - 1);

		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));

		return sf.format(calendar.getTime());

	}

	/**
	 * @return 本月第一天
	 */
	public String firstMonth() {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Calendar c = Calendar.getInstance();
		c.add(Calendar.MONTH, 0);
		c.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
		String first = format.format(c.getTime());
		return first;
	}

	/**
	 * @return 本月最后一天
	 */
	public String lastMonth() {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Calendar ca = Calendar.getInstance();
		ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
		String last = format.format(ca.getTime());
		return last;
	}



}
